package sort;

/**
 * 冒泡排序，交换相邻数组元素
 * Created by JiaJia on 2019/8/13 0013.
 */
public class Maopao {
    public static void main(String[] args) {
        int[] nums={5,1,6,3,11,7,9,2,13};
        maopao(nums);
        for (int i = 0; i <nums.length ; i++) {
            System.out.println(nums[i]);
        }
    }
    private static void maopao(int[] nums){
        for (int i = nums.length-1; i >0 ; i--) {
            for (int j = 0; j <i ; j++) {
                if (nums[j]>nums[j+1]){
                    swap(nums,j,j+1);
                }
            }
        }
    }
    private static void swap(int[] nums,int i,int j){
        int tmp=nums[i];
        nums[i]=nums[j];
        nums[j]=tmp;
    }


}